package com.stefan.lession04;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class ImageIconDemo extends JFrame {

    public ImageIconDemo(){
        // 获取图片的地址
        JLabel jLabel = new JLabel("图片标签");
        URL url = ImageIconDemo.class.getResource("test.jpg");

        ImageIcon imageIcon = new ImageIcon(url);// 注意命名冲突
        jLabel.setIcon(imageIcon);
        jLabel.setHorizontalAlignment(SwingConstants.CENTER);

        Container contentPane = getContentPane();
        contentPane.add(jLabel);

        setVisible(true);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setBounds(100,100,200,200);
    }

    public static void main(String[] args) {
        new ImageIconDemo();
    }
}
